package com.xmut.service.impl;

import com.xmut.mapper.UserMapper;
import com.xmut.mapper.VolunteerMapper;
import com.xmut.pojo.User;
import com.xmut.pojo.Voluntary;
import com.xmut.pojo.VoluntaryAct;
import com.xmut.service.VolunteerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VolunteerServiceImpl implements VolunteerService {

    @Autowired
    private VolunteerMapper volunteerMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<Voluntary> getVoluntaryById(Integer id) {
        return volunteerMapper.getVoluntaryById(id);
    }

    @Override
    public void insertVoluntary(Voluntary voluntary) {
        volunteerMapper.insertVoluntary(voluntary);
    }

    @Override
    public void deleteVoluntary(Integer id) {
        volunteerMapper.deleteVoluntary(id);
    }

    @Override
    public Voluntary getVoluById(Integer id) {
        return volunteerMapper.getVoluById(id);
    }

    @Override
    public void updateVoluntary(Integer id, Voluntary voluntary) {
        voluntary.setId(id);
        volunteerMapper.updateVoluntary(voluntary);
    }

    @Override
    public List<Voluntary> getAllVoluntary() {
        return volunteerMapper.getAllVoluntary();
    }

    @Override
    public void insertVolAct(VoluntaryAct voluntaryAct) {
        User user = userMapper.getVolunteerInfo(voluntaryAct.getUserid());
        Voluntary voluntary = volunteerMapper.getVoluById(voluntaryAct.getVoluntaryid());
        voluntaryAct.setUsername(user.getUsername());
        voluntaryAct.setVoluntarytitle(voluntary.getTitle());
        volunteerMapper.insertVolAct(voluntaryAct);
    }

    @Override
    public List<VoluntaryAct> getAllVolAct() {
        return volunteerMapper.getAllVolAct();
    }

    @Override
    public void delVolAct(Integer id) {
        volunteerMapper.delVolAct(id);
    }
}
